package com.huike.pmps.controller;

import com.alibaba.fastjson.JSONObject;
import com.huike.pmps.model.dto.common.PageInfo;
import com.huike.pmps.model.entity.Supplier;
import com.huike.pmps.model.entity.SupplierEvaluates;
import com.huike.pmps.model.vo.Result;
import com.huike.pmps.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
@Api(tags = "供应商管理")
@RestController
@RequestMapping("/api/suppliers")
public class SupplierController {

    @Autowired
    SupplierService supplierService;

    @ApiOperation(value = "添加供应商", httpMethod = "POST")
    @PostMapping
    public Result insertOne(Supplier supplier) {
        return supplierService.insertOne(supplier);
    }

    @ApiOperation(value = "获取供应商详细信息", httpMethod = "GET")
    @GetMapping("{id}")
    public Result selectOneById(@PathVariable("id") Integer id) {
        return supplierService.selectOneById(id);
    }


    @ApiOperation(value = "根据供应商ID删除供应商数据", httpMethod = "DELETE")
    @DeleteMapping("/{supplierId}")
    public Result deleteByRoleId(@PathVariable("supplierId") Integer supplierId) {
        return supplierService.deleteById(supplierId);
    }


    @ApiOperation(value = "根据供应商ID，修改供应商信息", httpMethod = "PUT")
    @PutMapping
    public Result updateById(Supplier supplier) {
        return supplierService.updateById(supplier);
    }


    @ApiOperation(value = "供应商启用或禁用", httpMethod = "PATCH")
    @ApiImplicitParam(name = "state", value = "供应商状态", paramType = "query", dataType = "int", required = true)
    @PatchMapping("/state/{supplierId}")
    public Result updateStateByRoleId(@PathVariable("supplierId") Integer supplierId, Integer state) {
        Supplier supplier = Supplier.builder().id(supplierId).state(state).build();
        return supplierService.updateById(supplier);
    }

    @ApiOperation(value = "按搜索条件分页查询", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "supplierName", value = "供应商名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "supplierTypeId", value = "供应商类型ID", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "provinceName", value = "所属区域", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "serviceTypeName", value = "服务范围", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "contractState", value = "合同状态", paramType = "query", dataType = "String")
    })
    @GetMapping
    public Result selectByCondition(PageInfo pageInfo, String supplierName, Integer supplierTypeId, String provinceName, String serviceTypeName,String contractState) {
        return supplierService.selectByCondition(pageInfo, supplierName, supplierTypeId, provinceName,serviceTypeName, contractState);
    }

    @ApiOperation(value = "按供应商类型查找供应商", httpMethod = "GET")
    @GetMapping("/supplier_type/{supplierTypeId}")
    public Result selectBySupplierType(@PathVariable("supplierTypeId") Integer supplierTypeId) {
        return supplierService.selectBySupplierType(supplierTypeId);
    }

}
